package beanstao.util;

import java.sql.Time;
import java.sql.Timestamp;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 用来处理时间日期字符串等相关的助手类<br>
 * 调用Main方法观看各方法的使用。
 * 
 * @author beanstao@google.com 
 * @version 2.0
 * @date 2010-08-15 13:08:52
 */
public class Dates
{

	// 计算某个区间的起始天的0点(起始时间) ================================

	/**
	 * 获取今天所在半月度的第一天(一般为1号或15号)
	 * 
	 * @return
	 */
	public static Date dayHalfOfMonth()
	{
		int year = nowYear();
		int month = nowMonth();
		int day = nowToday();
		StringBuilder sb = new StringBuilder(8);
		if (month >= 10)
		{
			sb.append(year);
			sb.append(month);
			if (day <= 15)
				sb.append("01");
			else
				sb.append("16");
			return parseShort(sb.toString());
		}
		else
		{
			sb.append(year);
			sb.append(0);
			sb.append(month);
			if (day <= 15)
				sb.append("01");
			else
				sb.append("16");
			return parseShort(sb.toString());
		}
	}

	/**
	 * 获取当前的半年度的第一天
	 * 
	 * @return
	 */
	public static Date dayHalfOfYear()
	{
		int m = nowMonth();
		if (m <= 6)
			return parseShort(nowYear() + "0101");
		else
			return parseShort(nowYear() + "0701");
	}

	/**
	 * 获取当前小时的开始时间
	 * 
	 * @return
	 */
	public static Date dayHour()
	{
		Calendar day = Calendar.getInstance();
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}

	/**
	 * 获取当前小时的开始时间
	 * 
	 * @return
	 */
	public static Date dayLastHour()
	{
		Calendar day = Calendar.getInstance();
		day.add(Calendar.HOUR, -1);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}

	/**
	 * 获取去年的第一天
	 * 
	 * @return
	 */
	public static Date dayLastYear()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(nowYear() - 1);
		sb.append("0101000000");
		return parseSimple(sb.toString());
	}

	/**
	 * 获取当前月的第一天
	 * 
	 * @return
	 */
	public static Date dayMonth()
	{
		int year = nowYear();
		int month = nowMonth();
		StringBuilder sb = new StringBuilder(8);
		if (month >= 10)
		{
			sb.append(year);
			sb.append(month);
			sb.append("01");
			return parseShort(sb.toString());
		}
		else
		{
			sb.append(year);
			sb.append(0);
			sb.append(month);
			sb.append("01");
			return parseShort(sb.toString());
		}
	}

	/**
	 * 获取当前季的第一天
	 * 
	 * @return
	 */
	public static Date daySeason()
	{
		int i = nowSeason();
		switch (i)
		{
			case 1:
				return parseSimple(nowYear() + "0101000000");
			case 2:
				return parseSimple(nowYear() + "0401000000");
			case 3:
				return parseSimple(nowYear() + "0701000000");
			case 4:
				return parseSimple(nowYear() + "1001000000");
		}
		return null;
	}

	/**
	 * 获取今天开始时间
	 * 
	 * @return
	 */
	public static Date dayToday()
	{
		Calendar day = Calendar.getInstance();
		day.set(nowYear(), nowMonth() - 1, nowToday(), 0, 0, 0);
		return day.getTime();
	}

	/**
	 * 获取本周的第一天(星期一)
	 * 
	 * @return
	 */
	public static Date dayWeek()
	{
		int offset = -1;
		int w = nowDayOfWeek();
		if (w > 0)
			offset = w - 1;
		else
			offset = 6;
		Calendar day = Calendar.getInstance();
		day.add(Calendar.DAY_OF_MONTH, -offset);
		day.set(day.get(Calendar.YEAR), day.get(Calendar.MONTH), day.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
		return day.getTime();
	}

	/**
	 * 获取当年的第一天
	 * 
	 * @return
	 */
	public static Date dayYear()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(nowYear());
		sb.append("0101000000");
		return parseSimple(sb.toString());
	}

	/**
	 * 获取今天的昨天
	 * 
	 * @return
	 */
	public static Date dayYestoday()
	{
		Calendar day = Calendar.getInstance();
		day.set(nowYear(), nowMonth() - 1, nowToday() - 1, 0, 0, 0);
		return day.getTime();
	}

	/**
	 * 获取今天的前n天
	 * 
	 * @return
	 */
	public static Date dayYestoday(int n)
	{
		Calendar day = Calendar.getInstance();
		day.set(nowYear(), nowMonth() - 1, nowToday() - n, 0, 0, 0);
		return day.getTime();
	}

	/**
	 * 获取上个月的今天
	 * 
	 * @return
	 */
	public static Date dayYestoMounth()
	{
		Calendar day = Calendar.getInstance();
		day.set(nowYear(), nowMonth() - 2, nowToday(), 0, 0, 0);
		return day.getTime();
	}

	// = 计算相差值 ===============================================================

	/**
	 * 两个日期相差的天
	 * 
	 * @param left
	 * @param right
	 * @return
	 */
	public static long diffDays(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);

		long timeDiffMillis = c2.getTimeInMillis() - c1.getTimeInMillis();

		// 两个日期相差的天
		return timeDiffMillis / (1000 * 60 * 60 * 24);
	}

	/**
	 * 两个日期相差的小时
	 * 
	 * @param left
	 * @param right
	 * @return
	 */
	public static long diffHours(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);

		long timeDiffMillis = c2.getTimeInMillis() - c1.getTimeInMillis();

		// 两个日期相差的小时
		return timeDiffMillis / (1000 * 60 * 60);
	}

	/**
	 * 两个日期相差的毫秒数
	 * 
	 * @param left
	 * @param right
	 * @return
	 */
	public static long diffMillis(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);

		// 两个日期相差的毫秒数
		return c2.getTimeInMillis() - c1.getTimeInMillis();
	}

	/**
	 * 两个日期相差的分钟
	 * 
	 * @param left
	 * @param right
	 * @return
	 */
	public static long diffMinutes(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);
		long timeDiffMillis = c2.getTimeInMillis() - c1.getTimeInMillis();
		// 两个日期相差的分钟
		return timeDiffMillis / (1000 * 60);
	}

	/**
	 * 两个日期相差的秒数
	 * 
	 * @param left
	 * @param right
	 * @return
	 */
	public static long diffSeconds(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);
		long timeDiffMillis = c2.getTimeInMillis() - c1.getTimeInMillis();
		// 两个日期相差的秒数
		return timeDiffMillis / 1000;
	}

	// = 将时间格式化成一个字符串 ==================================================

	/**
	 * 将一个指定的类型转换成通用的字符串格式(yyyy-MM-dd HH:mm:ss)
	 * 
	 * @param date
	 * @return
	 */
	public static String formatGeneral(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}

	/**
	 * 将一个指定的类型转换成缩写字符串格式(不带毫秒)(yyyyMMddHHmmss)
	 * 
	 * @param date
	 * @return
	 */
	public static String formatShort(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(date);
	}

	/**
	 * 将一个指定的类型转换成缩写字符串格式(带毫秒)(yyyyMMddHHmmssS)
	 * 
	 * @param date
	 * @return
	 */
	public static String formatShortS(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(date);
	}

	public static String formatShortsS(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
		return sdf.format(date);
	}

	public static String formatYM(Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
		return sdf.format(date);
	}

	public static String formatYMD(Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		return sdf.format(date);
	}

	public static String formatY_M_D(Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}

	/**
	 * 从一个指定的日期类型中返回一个年月日的int值
	 * 
	 * @param date
	 * @return
	 */
	public static int formatDateToInt(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		return Integer.parseInt(sdf.format(date));
	}

	/**
	 * 从一个指定的日期类型中返回一个小时的int值
	 * 
	 * @param date
	 * @return
	 */
	public static int formatHourToInt(final Date date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("H");
		return Integer.parseInt(sdf.format(date));
	}

	// = Timestamp(时间戳)相关 ==================================================

	/**
	 * 从指定Timestamp(时间戳)中得到相应的日期
	 */
	public static String formatTimestamp(final Timestamp datetime)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(datetime).toString();
	}

	/**
	 * 将指定Date转换为 Timestamp
	 * 
	 * @param date
	 *            指定日期格式为 "yyyy-MM-dd HH:mm:ss"
	 */
	public static Timestamp getTimestamp(final String date) throws Exception
	{
		return Timestamp.valueOf(date);
	}

	// = 从指定的时间中获得一些信息值 ==================================================

	public static int intDay(Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.DAY_OF_MONTH);
	}

	public static int intMonth(Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.MONTH) + 1;
	}

	public static int intWeek(Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.WEEK_OF_YEAR);
	}

	public static int intSeason(Date date)
	{
		switch (intMonth(date))
		{
			case 1:
			case 2:
			case 3:
				return 1;
			case 4:
			case 5:
			case 6:
				return 2;
			case 7:
			case 8:
			case 9:
				return 3;
			case 10:
			case 11:
			case 12:
				return 4;
		}
		return -1;
	}

	public static int intYear(Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.YEAR);
	}

	/**
	 * 从一个日期时间里获取小时
	 * 
	 * @return
	 */
	public static int intHour(final Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 从一个常用的时间格式字符串(yyyy-mm-dd hh:mm:ss)里获取小时
	 * 
	 * @return
	 */
	public static int intHour(final String date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(parse(date));
		return day.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 从一个日期时间里获取分钟
	 * 
	 * @return
	 */
	public static int intMinute(final Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.MINUTE);
	}

	/**
	 * 从一个常用的时间格式字符串(yyyy-mm-dd hh:mm:ss)里获取分钟
	 * 
	 * @return
	 */
	public static int intMinute(final String date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(parse(date));
		return day.get(Calendar.MINUTE);
	}

	/**
	 * 从一个日期时间里获取秒
	 * 
	 * @return
	 */
	public static int intSecond(final Date date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(date);
		return day.get(Calendar.SECOND);
	}

	/**
	 * 从一个常用的时间格式字符串(yyyy-mm-dd hh:mm:ss)里获取秒
	 * 
	 * @return
	 */
	public static int intSecond(final String date)
	{
		Calendar day = Calendar.getInstance();
		day.setTime(parse(date));
		return day.get(Calendar.SECOND);
	}

	// = 一些判断 ==================================================

	/**
	 * 是否闰年
	 */
	public static boolean isLeapYear(final int year)
	{
		return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
	}

	/**
	 * 返回两个时间谁先谁后
	 * 
	 * @param left
	 * @param right
	 * @return 如果left在right之后，返回false;反之,返回true;
	 */
	public static boolean isLeftBeforeRight(final Date left, final Date right)
	{
		Calendar c1 = Calendar.getInstance();
		c1.setTime(left);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(right);
		// 比较两个日期先后
		return c1.before(c2);
	}

	// = 当前时间往后的时间的获取 =========================================

	/**
	 * 获取当前时间的指定个小时的起始时间（可以为负数，负数为回推时间）
	 * 
	 * @param i
	 *            必须是整数的字符串形式，可以为负数。否则将获取的是当前时间。
	 * @return
	 */
	public static Date nextHour(String i)
	{
		int n = 0;
		try
		{
			n = Integer.parseInt(i);
		}
		catch (Exception e)
		{
		}

		Calendar day = Calendar.getInstance();
		day.add(Calendar.HOUR_OF_DAY, n);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}
	
	public static Date atHour(String i)
	{
		int n = 0;
		try
		{
			n = Integer.parseInt(i);
		}
		catch (Exception e)
		{
		}

		Calendar day = Calendar.getInstance();
		day.set(Calendar.HOUR_OF_DAY, n);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}
	
	public static Date nextDayatHour(String i)
	{
		int n = 0;
		try
		{
			n = Integer.parseInt(i);
		}
		catch (Exception e)
		{
		}

		Calendar day = Calendar.getInstance();
		day.add(Calendar.DATE, 1);
		day.set(Calendar.HOUR_OF_DAY, n);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}

	public static Date nextDay(String i)
	{
		int n = 0;
		try
		{
			n = Integer.parseInt(i);
		}
		catch (Exception e)
		{
		}

		Calendar day = Calendar.getInstance();
		day.add(Calendar.DATE, n);
		day.add(Calendar.HOUR_OF_DAY, 0);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}

	/**
	 * @return 获取当前时间的下一个小时的起始时间
	 */
	public static Date nextHour()
	{
		return nextHour("1");
	}

	/**
	 * @return 获取当前时间的下一个小时的指定起始时间
	 */
	public static Date nextHour(final int minute)
	{
		Calendar day = Calendar.getInstance();
		day.add(Calendar.HOUR_OF_DAY, 1);
		day.set(Calendar.MINUTE, minute);
		day.set(Calendar.SECOND, 0);
		return day.getTime();
	}

	// = 当前时间相关 ===================================================

	/**
	 * 获取今天即时时间
	 * 
	 * @return
	 */
	public static Date now()
	{
		Date now = new Date();
		now.setTime(System.currentTimeMillis());
		return now;
	}

	/**
	 * 获取今天即时时间
	 * 
	 * @return
	 */
	public static Time nowTime()
	{
		return subTime(now());
	}

	/**
	 * 获取今天是周几? ( 周日为 0 )
	 * 
	 * @return
	 */
	public static int nowDayOfWeek()
	{
		Calendar day = Calendar.getInstance();
		int dayOfWeek = day.get(Calendar.DAY_OF_WEEK) - 1;
		return dayOfWeek;
	}

	/**
	 * 获取当前小时
	 * 
	 * @return
	 */
	public static int nowHour()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 获取当前分钟
	 * 
	 * @return
	 */
	public static int nowMinute()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.MINUTE);
	}

	/**
	 * 获取当前月份(实际月份数字，从Java的Calendar类型中获取的月份数字是从零开始)
	 * 
	 * @return
	 */
	public static int nowMonth()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.MONTH) + 1;
	}

	/**
	 * 获取当前季度
	 * 
	 * @return
	 */
	public static int nowSeason()
	{
		switch (nowMonth())
		{
			case 1:
			case 2:
			case 3:
				return 1;
			case 4:
			case 5:
			case 6:
				return 2;
			case 7:
			case 8:
			case 9:
				return 3;
			case 10:
			case 11:
			case 12:
				return 4;
		}
		return -1;
	}

	/**
	 * 获取当前秒
	 * 
	 * @return
	 */
	public static int nowSecond()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.SECOND);
	}

	/**
	 * 得到当前时间的时间戳
	 * 
	 * @return 当前时间戳
	 */
	public static Timestamp nowTimestamp()
	{
		long curTime = System.currentTimeMillis();
		return new Timestamp(curTime);
	}

	/**
	 * 获取当前天，即今天是几号
	 * 
	 * @return
	 */
	public static int nowToday()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获取当前的时间转换为一般格式后的字符串。("yyyy-MM-dd HH:mm:ss")
	 * 
	 * @return
	 */
	public static String nowToGeneralLongString()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(now());
	}

	/**
	 * 获取当前的时间转换为最简单的格式后的字符串，类时间戳。("yyyyMMddHHmmssS")
	 * 
	 * @return
	 */
	public static String nowToSimpleLongString()
	{
		return formatShortS(now());
	}

	/**
	 * 获取当前的时间转换为最简单的格式后的字符串，类时间戳。("yyyyMMddHHmmss")
	 * 
	 * @return
	 */
	public static String nowToSimpleString()
	{
		return formatShort(now());
	}

	/**
	 * 获取当前周(面向年而言)
	 * 
	 * @return
	 */
	public static int nowWeek()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.WEEK_OF_YEAR);
	}

	/**
	 * 获取当前年
	 * 
	 * @return
	 */
	public static int nowYear()
	{
		Calendar day = Calendar.getInstance();
		return day.get(Calendar.YEAR);
	}

	// = 从字符串中解析时间 ===========================================================

	/**
	 * 将常用的时间格式字符串(yyyy-mm-dd HH:mm:ss)转换为日期对象
	 * 
	 * @param dateStr
	 *            常用的时间格式字符串(yyyy-MM-dd HH:mm:ss)
	 * @return
	 */
	public static Date parse(final String dateStr)
	{
		return parse(dateStr, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 将指定的日期字符串转化为日期对象
	 * 
	 * @param dateStr
	 *            日期字符串
	 * @return java.util.Date
	 */
	public static Date parse(final String dateStr, final String format)
	{
		if ((dateStr == null) || (format == null))
			return null;
		SimpleDateFormat df = new SimpleDateFormat(format);
		try
		{
			Date date = df.parse(dateStr);
			return date;
		}
		catch (Exception ex)
		{
			return null;
		}
	}

	/**
	 * 将短时间格式字符串(yyyyMMdd)转换为日期对象
	 * 
	 * @param strDate
	 *            短时间格式字符串(yyyyMMdd)
	 * @return
	 */
	public static Date parseShort(final String strDate)
	{
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		ParsePosition pos = new ParsePosition(0);
		Date strtodate = formatter.parse(strDate, pos);
		return strtodate;
	}

	/**
	 * 将指定的日期字符串(yyyyMMddHHmmss)转化为日期对象
	 * 
	 * @param dateStr
	 *            日期字符串
	 * @return java.util.Date
	 */
	public static Date parseSimple(final String dateStr)
	{
		return parse(dateStr, "yyyyMMddHHmmss");
	}

	// = 一些小方法
	// ========================================================================

	/**
	 * 获得一个日期类型(Date)中的时间类型(Time)
	 * 
	 * @param date
	 * @return
	 */
	public static Time subTime(final Date date)
	{
		StringBuilder sb = new StringBuilder();
		int hour = intHour(date);
		sb.append(hour).append(":");
		sb.append(intMinute(date)).append(":");
		sb.append(intSecond(date));
		return Time.valueOf(sb.toString());
	}

	protected Dates()
	{
	}

	@SuppressWarnings("deprecation")
	public static void main(final String[] args)
	{
		System.out.println("当前年：" + nowYear());
		System.out.println("当前季：" + nowSeason());
		System.out.println("当前月：" + nowMonth());
		System.out.println("当前周：" + nowWeek());
		System.out.println("周几了：" + nowDayOfWeek());
		System.out.println("当前天：" + nowToday());
		System.out.println("当前时：" + nowHour());
		System.out.println("当前分：" + nowMinute());
		System.out.println("当前秒：" + nowSecond());
		System.out.println("======");
		System.out.println("　去年的第一天：" + dayLastYear().toLocaleString());
		System.out.println("　今年的第一天：" + dayYear().toLocaleString());
		System.out.println("现半年的第一天：" + dayHalfOfYear().toLocaleString());
		System.out.println("当前季的第一天：" + daySeason().toLocaleString());
		System.out.println("当前月的第一天：" + dayMonth().toLocaleString());
		System.out.println("　半月的第一天：" + dayHalfOfMonth().toLocaleString());
		System.out.println("当前周的第一天：" + dayWeek().toLocaleString());
		System.out.println("　　　　　昨天：" + dayYestoday().toLocaleString());
		System.out.println("　　　今天零时：" + dayToday().toLocaleString());
		System.out.println("　　上一个小时：" + dayLastHour().toLocaleString());
		System.out.println("　　　　本小时：" + dayHour().toLocaleString());
		System.out.println("　　　今天即时：" + now().toLocaleString());
		System.out.println("=========");
		System.out.println("　　　简时间串：" + formatShort(now()));
		System.out.println("　　　下一小时：" + nextHour().toLocaleString());
		System.out.println("=========");

		Date dateLeft = parseSimple("20100312181818");
		System.out.println("dateLeft >> " + dateLeft.toLocaleString());
		Date dateRight = parseSimple("20100312080808");
		System.out.println("dateRight >> " + dateRight.toLocaleString());
		System.out.println("如果left在right之后，返回false;反之,返回true;");
		System.out.println("dateLeft(左)与dateRight(右)谁先谁后>>>> " + isLeftBeforeRight(dateLeft, dateRight));
		System.out.println("dateLeft(左)与dateRight(右)的小时间隔>>>> " + diffHours(dateLeft, dateRight));
		System.out.println("dateLeft(左)的子Time: " + subTime(dateLeft));
		System.out.println("dateRight(右)的子Time: " + subTime(dateRight));
		System.out.println("=========");

		System.out.println(subTime(Dates.parse("1998-12-31 00:00:01")));
		System.out.println("=========");
		System.out.println(subTime(Dates.parse("1998-12-31 10:59:01")));
		System.out.println("=========");
		System.out.println(subTime(Dates.parse("1998-12-31 11:59:01")));
		System.out.println("=========");
		System.out.println(subTime(Dates.parse("1998-12-31 12:00:01")));
		System.out.println("=========");
		System.out.println(subTime(Dates.parse("1998-12-31 13:00:01")));
		System.out.println("=========");
		System.out.println(subTime(Dates.parse("1998-12-31 23:59:59")));

		System.out.println("=========");
		System.out.println(formatDateToInt(Dates.parse("1998-12-31 23:59:59")));
		System.out.println(formatHourToInt(Dates.parse("1998-12-31 01:59:59")));
	}

}
